-
Notifications
You must be signed in to change notification settings - Fork 212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Payroll: handle both cases of extra salary being sent to accrued balance #912
Conversation
@@ -660,11 +660,14 @@ contract Payroll is EtherTokenConstant, IForwarder, IsContract, AragonApp { | |||
// If they're being paid an amount that doesn't match perfectly with the adjusted time | |||
// (up to a seconds' worth of salary), add the second and put the extra remaining salary | |||
// into their accrued salary | |||
uint256 extraSalary = currentSalaryPaid % salary; | |||
// The extra check is to handle the case where someone requested less than one second of their salary | |||
uint256 extraSalary = currentSalaryPaid < salary ? salary - currentSalaryPaid : currentSalaryPaid % salary; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
salary - extraSalary
should go to acrued salary in case when currentSalaryPaid > salary
I think the following code should work fine, or am I missing something?
uint256 extraSalary = currentSalaryPaid % salary;
if (extraSalary > 0) {
timeDiff = timeDiff.add(1);
employee.accruedSalary = salary - extraSalary;
}
Examples:
Salary == 10
and you want to getcurrentSalaryPaid == 21
.
Time difference would be 3. Contract will transfercurrentSalaryPaid == 21
and 10 - 21%10 = 9 will go to the accrued salary.Salary == 10
and you want to getcurrentSalaryPaid == 1
.
Time difference would be 1. Contract will transfercurrentSalaryPaid == 1
and 10 - 1%10 = 9 will go to the accrued salary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes... this is a good catch. I think the current state doesn't represent the
currentSalaryPaid == 21
and 10 - 21%10 = 9
case correctly; it'd put 1
into the accrued salary instead of 9.
cc @facuspagnuolo may also want to double check this, but your judgement on this simplification seems correct @Corsaire :).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, we were close in our first attempt here haha 😅
Handles both the cases, where someone may: